package 栈和队列;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;
import java.util.Vector;

public class SuffixExpress {
	static Stack<Character> stack =new Stack<>();
	static List<Character> list = new ArrayList<>();
	static Vector<Character> vector=new Vector<>();
	static Vector<Character> v=new Vector<>();
	public static void main(String args[]) {
		System.out.println("输入str的值");
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		checkStr(str);

	}

	private static void checkStr(String str) {
		// TODO Auto-generated method stub
		vector.add((Character.valueOf('+')));
		vector.add((Character.valueOf('-')));
		vector.add((Character.valueOf('*')));
		vector.add((Character.valueOf('/')));
		v.add('(');
		v.add(')');
		for(int i=0;i<str.length();i++) {
			char tmp = str.charAt(i);
			if(!vector.contains(tmp) &&tmp!='(' && tmp!=')') {
				list.add(tmp);

			}else if(tmp==')'){
				while(stack.peek()!='(') {
					list.add(stack.pop());

				}
				stack.pop();//弹出(括号
			}else {
				if(tmp=='-'||tmp=='+') {
					if(!stack.isEmpty()&&tmp!='('&&stack.peek()!='(') {
						list.add(stack.pop());

					}
				}
				stack.push(tmp);


			}
		}
		while(!stack.isEmpty()) {
			if(v.contains(stack.peek())){
				System.out.println("等式有误");
			}
			list.add(stack.pop());
		}
		System.out.println(list);

		System.out.println(checkList(list));


	}

	private static boolean checkList(List<Character> list) {
		// TODO Auto-generated method stub
		int count=0;
		int num=0;
		int ca=0;
		for(Character e:list) {
			if(vector.contains(e)) {
				if(count==2) {

					count=0;
					num++;
				}else if(num==2){
					count=0;
					ca++;
					num=0;
				}else if(ca==1&&count==1){

				}
				else {
					return false;
				}

			}else {
				count++;
			}
			System.out.println("count:"+count +",num:" +num);
		}
		return true;
	}

}
